<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function TreeNode(val, left, right) {
            this.val = val === undefined ? 0 : val
            this.left = left === undefined ? null : left
            this.right = right === undefined ? null : right
        }

        function maxDeep(root) {
            if (root == null) {
                return 0
            } else {
                let leftDeep = maxDeep(root.left)
                let rightDeep = maxDeep(root.right)
                return Math.max(leftDeep, rightDeep) + 1
            }
        }

        let root = new TreeNode(3);
        root.left = new TreeNode(9);
        root.right = new TreeNode(20);
        root.right.left = new TreeNode(15);
        root.right.right = new TreeNode(7);
        console.log(maxDepth(root)); 
    </script>
</body>

</html>